#include "RandomTimeEmitter.h"

void RandomTimeEmitter::randomEmitTime()
{
	nextEmissionTime = randomInt(minEmitTime, maxEmitTime);
}

int RandomTimeEmitter::randomInt(int low, int high)
{
	int randomInt = rand() % high;
    if(randomInt < low)
    {
    	randomInt = low;	
    }
    return randomInt;
}

RandomTimeEmitter::RandomTimeEmitter(CubePileGrid * aCubePiles, int aMinEmitTime, int aMaxEmitTime)
{
	cubePiles = aCubePiles;
	timeSinceLastEmission = 0;
	maxEmitTime = aMaxEmitTime;
	minEmitTime = aMinEmitTime;
    randomEmitTime();
}

void RandomTimeEmitter::emit(float timeD)
{
	timeSinceLastEmission += (int)timeD;
	if(timeSinceLastEmission >= nextEmissionTime)
	{
		emitTo(cubePiles);
		randomEmitTime();
		timeSinceLastEmission = 0;
	}
}
